use "SSI.dta" 

*create treatment variables; code takes all those who responded to the 1st manipulation check question 
*for that treatment and assigns them to that treatment condition

**Dog article [What animal is discussed in the article?]
gen control=0
replace control=1 if q53 !=.
tab control

**Terrorism article [What issue was discussed in the article?]
gen terror=0
replace terror=1 if q57 !=.
tab terror

**Clinton article [What issue was discussed in the article?]
gen terror_clinton=0
replace terror_clinton=1 if q58 !=.
tab terror_clinton

**Trump article [What issue was discussed in the article?]
gen terror_trump=0
replace terror_trump=1 if q59 !=.
tab terror_trump

**Clinton & Trump article [What issue was discussed in the article?]
gen terror_clintontrump=0
replace terror_clintontrump=1 if q60 !=.
tab terror_clintontrump

**generate treatment variable coded 1=dog/control; 2=TT; 3=TT-C; 4=TT-T; 5=TT-both
gen treatment=.
recode treatment .=1 if control==1
recode treatment .=2 if terror==1
recode treatment .=3 if terror_clinton==1
recode treatment .=4 if terror_trump==1
recode treatment .=5 if terror_clintontrump==1

label define treatment 1 "control" 2 "terror" 3 "terror_c" 4 "terror_t" 5 "terror_both"
label values treatment treatment

**predispositions (were asked at end of survey)
*lib-con 7-point scale
gen libcon=q27
*pid dummies
recode q28 1=1 2/3=0, gen(pid_rep)
recode q28 1=0 2=1 3=0, gen(pid_dem)
recode q28 1/2=0 3=1, gen(pid_indep)
*6-point pid measure [1=strong rep 2=weak rep 3=close rep 4=close dem 5=weak dem 6=strong dem]
*note this is not a 7pt b/c we didn't allow the leaners to stay independent (a small number don't answer but no "neither" option was given)
gen pid7=.
recode pid7 .=1 if q29==1
recode pid7 .=2 if q29==2
recode pid7 .=3 if q31==1
recode pid7 .=4 if q31==2
recode pid7 .=5 if q30==2
recode pid7 .=6 if q30==1

*registered to vote
gen registered=q35
recode q35 1=1 2=0

*voted in 2012
gen voted2012=q37
recode voted2012 1=1 2/3=0

*plan to vote in 2016 or have already voted
*[1=plan to vote, 2=already voted, 3=no, 4=ineligible]
gen vote2016=q96

*watched debate on 9/26 (first pres debate); code maybe(3) to 0 along with no (2)
gen watcheddebate=q97
recode watcheddebate 1=1 2/3=0

**demographics (asked at beginning of survey)
*code age so that 1=18-24; 2=25-34; 3=35-44; 4=45-55; 5=55 and older
gen age=q121
recode age 12=1 13=2 14=3 15=4 16=5

gen female=q32
recode female 2=1 1=0

*region is coded 1=midwest; 2=ne; 3=south; 4=west
gen region=q128
recode region 1=1 2/4=0, gen(midwest)
recode region 1=0 2=1 3/4=0, gen(northeast)
recode region 1/2=0 3=1 4=0, gen(south)
recode region 1/3=0 4=1, gen(west)

*race/ethnicity is coded 1=black 2=native 3=asian 4=latino 5=white
gen race=q129
recode race 1=1 2/5=0, gen(black)
recode race 1=0 2/3=1 4/5=0, gen(race_other)
recode race 1/3=0 4=1 5=0, gen(latino)
recode race 1/4=0 5=1, gen(white)

*demographics asked after survey:
*education 1-8
gen education=q43
*income 1-12
gen income=q45
recode income 11=1 12=2 13=3 14=4 15=5 16=6 17=7 18=8 19=9 20=10 21=11 22=12
*have children
gen havechildren=q131
recode havechildren 1=1 2=0

*have female children
gen femalechildren=q132
recode femalechildren 1=0 2/3=0 .=0


*emotions
gen anger=q122_1
gen fear=q122_2
gen anxiety=q122_3
gen worry=q122_4
gen enthusiasm=q122_5
gen hope=q122_6
gen pride=q122_7
gen hate=q122_8
gen contempt=q122_9
gen bitterness=q122_10
gen resentment=q122_11

** Factor Analysis and plot
factor anger fear anxiety worry enthusiasm hope pride hate contempt bitterness resentment
loadingplot
** Loading plot after rotation
rotate
loadingplot

** Positive and Negative Emotions
predict emo_neg emo_pos
label variable emo_neg "Negative Emotions" 
label variable emo_pos "Positive Emotions" 

*leadership, etc. evals [1=7 agree/disagree scale initially; recoded here so that higher values=agree]
***note: q133 clashed in the import (I guess) with another q115 and was renamed var94; I've coded q115 as var94 below but this needs to be rechecked)
gen lead_c=q5
recode lead_c 1=7 2=6 3=5 5=3 6=2 7=1
gen lead_t=q6
recode lead_t 1=7 2=6 3=5 5=3 6=2 7=1
gen honest_c=q7
recode honest_c 1=7 2=6 3=5 5=3 6=2 7=1
gen honest_t=q8
recode honest_t 1=7 2=6 3=5 5=3 6=2 7=1
gen competent_c=q9
recode competent_c 1=7 2=6 3=5 5=3 6=2 7=1
gen competent_t=q10
recode competent_t 1=7 2=6 3=5 5=3 6=2 7=1
gen assertive_c=q15
recode assertive_c 1=7 2=6 3=5 5=3 6=2 7=1
gen assertive_t=var94
recode assertive_t 1=7 2=6 3=5 5=3 6=2 7=1
gen respectswomen_c=q114
recode respectswomen_c 1=7 2=6 3=5 5=3 6=2 7=1
gen respectswomen_t=q12
recode respectswomen_t 1=7 2=6 3=5 5=3 6=2 7=1

*handle foreign policy and national defense [1=not well at all; 2=not very well; 3=somewhat well; 4=extremely well
gen handlesforeign_c=q13
gen handlesforeign_t=q14

*diplomacy vs. force to solve int'l problems
gen dipvsforce=q15
*12% say they "haven't thought much about this, recode to missing*
recode dipvsforce 8=.

*gen banrefugees, and recode so that higher values=more in favor
gen banrefugees=q17
recode banrefugees 1=5 2=4 4=2 5=1

*variable measuring support for scope of operations against ISIS
*1=limited to only air strikes
*2=both air strikes and combat troops
*3=no action
gen scope_isisaction=q18

*feeling therms
gen feeling_c=q19_1
gen feeling_t=q19_2

*vote [1=clinton 2=trump 3=neither/not vote]
gen vote=q20
recode vote 1=1 2=0 3=0, gen(vote_c)
recode vote 1=0 2=1 3=0, gen(vote_t)
recode vote 1/2=0 3=1, gen(vote_none)

*vote follow up (asked to those who said none); create new variables that include the leaners
gen vote_c2=vote_c
recode vote_c2 0=1 if q21==1
gen vote_t2=vote_t
recode vote_t2 0=1 if q21==2

*knowledge [coding below codes knowledge of the party of each of these leaders as correct=1 or not correct/didn't answer=0]
gen know_c=q94_4
recode know_c 1=1 2/3=0
gen know_t =q94_5
recode know_t 1=0 2=1 3=0
gen know_pelosi=q94_6
recode know_pelosi 1=1 2/3=0
gen know_obama=q94_7
recode know_obama 1=1 2/3=0
gen know_rice=q94_8
recode know_rice 1=0 2=1 3=0
gen know_palin=q94_9
recode know_palin 1=0 2=1 3=0
gen know_romney=q94_10
recode know_romney 1=0 2=1 3=0
gen know_mcconnell=q94_11
recode know_mcconnell 1=0 2=1 3=0
gen know_bugs=q94_3
recode know_bugs 1/2=0 3=1

*knowledge of clinton's posts
gen knowclinton=q22
**need to code this still

*knowledge of trump's posts
gen knowtrump=q23
**need to code this still

*eval of candidate's experience
*we also have questions on all other leaders but I'm coding for c and t only right now
*1=none at all; 2=a little; 3=some experience; 4=a lot of experience 5=don't know
*code don't know to .
gen experience_c=q95_4 
recode experience_c 5=.
gen experience_t=q95_5
recode experience_t 5=.

*gender norms [1=strongly disagree 2=disagree 3=agree 4=strongly agree]
gen menbetterleaders=q24_1
gen menbetterforeignpolicy=q24_2

*compliance check at the end: what was the topic of the article that you read about?
gen compliance=q98
recode compliance 4=1 5/8=0, gen(compliance_dog)
recode compliance 4=0 5=1 6/8=0, gen(compliance_tt)
recode compliance 4/5=0 6=1 7/8=0, gen(compliance_c)
recode compliance 4/6=0 7=1 8=0, gen(compliance_t)
recode compliance 4/7=0 8=1, gen(compliance_both)

sort treatment
by treatment: sum feeling_c
by treatment: sum feeling_t

*** Appendix Table 6: Descriptive Stats for SSI Data ***
by treatment, sort: gen freq=_N 
egen pct_female = mean(100 * (female==1)), by(treatment)
egen pct_white = mean(100 * (white==1)), by(treatment)
egen pct_south = mean(100 * (south==1)), by(treatment)
egen mean_id = mean(libcon), by(treatment)
tabdisp treatment, ///
cell(freq pct_female pct_white pct_south mean_id) format(%3.2f) 
esttab using Table6.rtf, replace star (* 0.10 ** 0.05 *** 0.01) label ///
b(2) p(2) r2(2) ///
title (Descriptive Stats for SSI Data) ///
addnote ("Source:SSI Data")


*** Appendix Table 7: Balance Checks ***
eststo: quietly logit control q121 q27 q43 q45 female south white pid7
eststo: quietly logit terror q121 q27 q43 q45 female south white pid7
eststo: quietly logit terror_clinton q121 q27 q43 q45 female south white pid7
eststo: quietly logit terror_trump q121 q27 q43 q45 female south white pid7
eststo: quietly logit terror_clintontrump q121 q27 q43 q45 female south white pid7
esttab using Table7.rtf, eform replace star (* 0.10 ** 0.05 *** 0.01) label ///
b(2) p(2) r2(2) ///
title (Descriptive Stats for SSI Data) ///
addnote ("Source:SSI Data")




**** if needed**** 
** Install blindschemes and coefplot package
*ssc install blindschemes, replace all
*ssc install coefplot, replace all
*set scheme plotplain

** Create Variable Labels Probit Models
label variable vote_c "Vote for Clinton"
label variable terror "Terror "
label variable terror_clinton "Terror (Clinton)"
label variable terror_trump "Terror (Trump)"
label variable terror_clintontrump "Terror (Both)"
label define tment 1 "Control" 2 "Terror" 3 "Terror (Clinton)" 4 "Terror (Trump)" ///
5 "Terror (Both)"
label values treatment tment



*** Figure 3: Terrorism & Leadership Evaluation ***
** Leadership by Treatment
eststo clinton: reg lead_c i.treatment
eststo trump: reg lead_t i.treatment
** Coefplot
coefplot (clinton), bylabel(Clinton Leadership) ///
|| (trump), bylabel(Trump Leadership) ///
||, drop(_cons) xline(0) xtitle(Regression Coefficient) ytitle(Treatments) levels(90)

graph save Figure3.gph, replace
graph export Figure3.png, replace width(1800)

eststo clear 

*** Appendix Table 8: Terrorism and Thermometer ***
** Feeling Thermometer by Treatment
eststo clinton: reg feeling_c i.treatment
eststo trump: reg feeling_t i.treatment

# delimit ;
esttab using Table8.rtf, nogap se b(%9.2f) starlevels(^ .10 * .05 ** .01 *** .001) r2(%9.2f) 
	title("Feeling Thermometer by Treatment" )
	nonumber mtitles ("Clinton" "Trump")
	 label
	addnote("Dependent variable")
	compress replace;
 #delimit cr


eststo clear


*** Appendix Table 9A: Heterogeneous Effect of Terrorism and ***
*** Candidate Experience on Feeling Thermometers of Clinton ***
*** Party and Gender ***

eststo dem_male: reg feeling_c i.treatment if female==0 & pid_dem==1
eststo rep_male: reg feeling_c i.treatment if female==0 & pid_rep==1
eststo dem_female: reg feeling_c i.treatment if female==1 & pid_dem==1
eststo rep_female: reg feeling_c i.treatment if female==1 & pid_rep==1
esttab using Table9a.rtf, replace star (* 0.10 ** 0.05 *** 0.01) label ///
b(2) p(2) r2(2) ///
title (Clinton Leadership by Treatment and Party ID among Females) ///
nonumber mtitles ("Democrats" "Republicans") ///
addnote ("Source:SSI Data")

eststo clear



*** Appendix Table 9B: Heterogeneous Effect of Terrorism and ***
*** Candidate Experience on Feeling Thermometers of Trump ***
*** Party and Gender ***

eststo dem_male: reg feeling_t i.treatment if female==0 & pid_dem==1
eststo rep_male: reg feeling_t i.treatment if female==0 & pid_rep==1
eststo dem_female: reg feeling_t i.treatment if female==1 & pid_dem==1
eststo rep_female: reg feeling_t i.treatment if female==1 & pid_rep==1
esttab using Table9b.rtf, replace  star (* 0.10 ** 0.05 *** 0.01) label ///
b(2) p(2) r2(2) ///
title (Clinton Leadership by Treatment and Party ID among Women) ///
nonumber mtitles ("Democrats" "Republicans") ///
addnote ("Source:SSI Data")

eststo clear
 

*** Appendix Figure 1: Emotion coefplot ***
** Emotions by Treatment
eststo pos: reg emo_pos i.treatment
eststo neg: reg emo_neg i.treatment
esttab, star (* 0.10 ** 0.05 *** 0.01) label ///
b(2) p(2) r2(2) ///
title(Emotions by Treatment) ///
nonumber mtitles ("Positive Emotions" "Negative Emotions") ///
addnote ("Source:SSI Data")
** Coefplot
coefplot (pos), bylabel(Positive Emotions) ///
|| (neg), bylabel(Negative Emotions) ///
||, drop(_cons) xline(0) xtitle(Regression Coefficient) ytitle(Treatment) levels(90)
graph save FigureAppendix1.gph, replace
graph export FigureAppendix1.png, replace width(1800)

eststo clear







